// pages/find/find.js
import { HTTP } from '../../utils/http.js'
let ajax = new HTTP()
var app = getApp()

Page({
    data: {
        imgUrls: [],
        classifyArr: [{
                iconUrl: './images/001.png',
                text: '赛事报名',
                id: '001'
            },
            {
                iconUrl: './images/002.png',
                text: '健身培训',
                id: '002'
            },
            {
                iconUrl: './images/003.png',
                text: '热门资讯',
                id: '003'
            },
            {
                iconUrl: './images/004.png',
                text: '视频',
                id: '004'
            }
        ],
        applyArr: [],
        placeType: 'apply'
    },
    onLoad () {
        let memberid = app.globalData.memberid
        wx.showLoading({
            title: '加载中',
        })
        this._getSwiperList(memberid)
        this._getApplyList(memberid)
    },
    onShow() {
        
    },
    // 转发 
    onShareAppMessage: function () {

    },
    // 搜索跳转
    onSearchTap (event) {
        wx.navigateTo({
            url: '/pages/search/search?id=' + this.data.placeType,
        })
    },
    // 点击轮播
    onSwiperTap (event) {
        let id = event.detail.id
        let title = event.detail.title
        wx.navigateTo({
            url: 'apply/apply?id=' + id + '&title=' + title
        })
    },
    // 进入分类
    enterClassify(event) {
        let classifyId = event.currentTarget.dataset.id
        if (classifyId === "002") {
            wx.navigateTo({
                url: 'fitness/fitness',
            })
        }
        if (classifyId === "003") {
            wx.navigateTo({
                url: 'news/news',
            })
        }
        if (classifyId === "004") {
            wx.navigateTo({
                url: 'vision/vision',
            })
        }
    },
    // 报名详情
    onApplyTap(event) {
        let applyId = event.currentTarget.dataset.applyid
        let applyTitle = event.currentTarget.dataset.title
        wx.navigateTo({
            url: 'apply/apply?id=' + applyId + '&title=' + applyTitle,
        })
    },
    // 请求轮播数据
    _getSwiperList(memberid) {
        ajax.request({
            url: "sportslist/banner",
            data: {
                memberid: memberid
            },
            success: (res) => {
                this.setData({
                    imgUrls: res.data
                })
            }
        })
    },
    // 请求发现数据
    _getApplyList(memberid) {
        ajax.request({
            url: "sportslist",
            data: {
                memberid: memberid
            },
            success: (res) => {
                if (res.rescode === "0000") {
                    wx.hideLoading()
                    this.setData({
                        applyArr: res.data
                    })
                }
            }
        })
    },
})